package com.bytedance.common.utility.collection;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import java.lang.ref.WeakReference;

public final class WeakHandler extends Handler {
    public interface Callback {
        void handleMsg(Message message);
    }

    private WeakReference<Callback> mRefCallback;

    public WeakHandler(Callback callback) {
        this.mRefCallback = new WeakReference(callback);
    }

    public WeakHandler(Looper looper, Callback callback) {
        super(looper);
        this.mRefCallback = new WeakReference(callback);
    }

    public final void handleMessage(Message message) {
        Callback callback = this.mRefCallback.get();
        if(callback != null && message != null) {
            callback.handleMsg(message);
        }
    }
}

